function ajaxFileUpload(id_file,id_show,hdf_path_image,action)
{
	if ($("input[type=file]").val() == ""){
		alert("Hãy chọn file upload ");
		return ;
	} 
          $.ajaxFileUpload
          (
             {
                 url:action,
                secureuri:false,
                fileElementId:id_file,
                dataType: 'json',
                success: function (data, status)
                {
            	 
                   if(typeof(data.error) != 'undefined')
                   {
                       console.log(data);
                      if(data.error == true)
                      {
                         alert(data.error);
                      }else
                      {
                         //alert(data.msg);
                         $("#"+ id_show).attr("src", data.path_file_full );
						 $("#"+hdf_path_image).val(data.path_file);
                      }
                   }
                },
                error: function (data, status, e)
                {
                   alert(e);
                }
             }
          )
          
          return false;

       }
	   
function show_large_img(ele){
	var id_ele = ele.attr("id");
	var index = id_ele.substring(id_ele.lastIndexOf('_') + 1,id_ele.length );
	
	$("#div_img_"+index).css("position","relative");
	
	$("#img_large_" + index).css("display","block");
	$("#img_large_" + index).css("position","absolute");
	$("#img_large_" + index).css("top",$("#img_small_" + index).position().top - 20);
	
	$("#img_large_" + index).css("left",$("#img_small_" + index).position().left +  $("#img_small_" + index).width() + 50  );
}

function hide_large_img(ele){
	var id_ele = ele.attr("id");
	var index = id_ele.substring(id_ele.lastIndexOf('_') + 1,id_ele.length );
		
	$("#img_large_" + index).css("display","none");
	
}

function slideSwitch() {
	
	
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
	$("#slideshow IMG").not(".active").css("opacity",0);
	$("#slideshow IMG").not(".last-active").css("opacity",0);
	
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, "slow", function() {
            $active.removeClass('active last-active');
        });
}
/** Function:
 		common.FormatCurrency: format number
 	Param:
 		str: string input
 	Return:
 		new string
 	Author: Thanh Phu
 **/
function FormatCurrency(strNumberToFormat)
{
		if(strNumberToFormat == '' || strNumberToFormat == null)
		{
			return 0;
		}
		else{
			
			strNumberToFormat = parseFloat(strNumberToFormat) ;
	
			
	        strNumberToFormat += '';
	        intFirstPartTemp = strNumberToFormat.split('.');
	        intFirstPart = intFirstPartTemp[0];
	        intSecondPart = intFirstPartTemp.length > 1 ? '.' + intFirstPartTemp[1] : '';
	        var objRegex = /(\d+)(\d{3})/;
	        while (objRegex.test(intFirstPart)) {
	                intFirstPart = intFirstPart.replace(objRegex, '$1' + ',' + '$2');
	        }
	        return intFirstPart + intSecondPart;
			//return intFirstPart
		}
}
function redirect_page (url){
	window.location = url;
}
function validate_update_product($type){
	var flag =true;
	
	if ($("input[type=file]").val() == "" && $type == "create"){
		$("input[type=file]").addClass("error");
		flag = false;
	}
	if ($("#txt_price").val() == "" || $("#txt_price").val() == 0){
		$("#txt_price").addClass("error");
		flag= false;
	}
	if (flag == false){
		$("#err_list").html("Hãy nhập các thông tin chưa hợp lệ. ");
	}
	return flag;
}